/**
 * 封装Radio
 * @author SPY
 * @date 2020/1/17
 */

import React from 'react';
import PropTypes from 'prop-types';
import { Radio } from 'antd';

class MyRadio extends React.Component {

    // 定义传入属性
    static propTypes = {
        options: PropTypes.array.isRequired,  // 需要展示的radio数据
    }

    // 定义传入属性的默认值
    static defaultProps = {
        options: [],
    }

    renderRadio = (item) => {
        return (
            <Radio key={item.value} value={item.value}>{item.label}</Radio>
        );
    }

    render() {
        const { options, ...restProps } = this.props;
        return (
            <Radio.Group
                {...restProps}
            >
                {
                    Array.isArray(options) && options.length > 0 && options.map(this.renderRadio)
                }
            </Radio.Group>
        );
    }
}

export default MyRadio;